<?php
include_once 'MySQLDAO.php';

/**
 * Definition of Class Roomrateperiods
 * This class represents a data access object for the database table 'roomrateperiods'.
 */
class Roomrateperiods {


	private $dao = null;

	private $i = 1;

	/**
	 * associated database field: ratePeriodCode, type: varchar, is nullable: false, character set: utf8, max length: 10
	 */
	private $ratePeriodCode  = 0;

	/**
	 * associated database field: ratePeriodDescription, type: varchar, is nullable: true, character set: utf8, max length: 45
	 */
	private $ratePeriodDescription;



	/**
	 * Default constructor
	 * @param value some value
	 */
	function __construct(){
		$this->dao = new MySQLDao("RoomRatePeriods");
	}


	/**
	 * Initialize the business object with data read from the DB.
	 * @param row database row array containing the values from one read record
	 */
	public function init($row){
		if(isset($row['ratePeriodCode'])) $this->ratePeriodCode = $row['ratePeriodCode'];
		if(isset($row['ratePeriodDescription'])) $this->ratePeriodDescription = $row['ratePeriodDescription'];
	}


	/**
	 * Returns the string representation for this object
	 * @param escapeQuotationMarks boolean value to indicate if quotation marks in value strings should be escaped, default value is true
	 * @return String String representation of Roomrateperiods
	 */
	public function toString($escapeQuotationMarks=true){
		$s = '[';
		$s .= 'ratePeriodCode: '.(($escapeQuotationMarks===true) ? addslashes($this->ratePeriodCode) : $this->ratePeriodCode).', ';
		$s .= 'ratePeriodDescription: '.(($escapeQuotationMarks===true) ? addslashes($this->ratePeriodDescription) : $this->ratePeriodDescription);
		$s .= ']';
		return $s;
	}


	/**
	 * Returns the JSON (JavaScript Object Notation) string representation for this object
	 * @return String JSON representation of Roomrateperiods
	 */
	public function toJSONString(){
		$fieldValues = array ("ratePeriodCode"=>$this->ratePeriodCode, "ratePeriodDescription"=>$this->ratePeriodDescription);
		return json_encode($fieldValues);
	}


	/**
	 * Returns a HTML representation of this object using DIVs for formatting via css
	 * @param escapeHTML boolean value to indicate if value strings should be html escaped, default value is true
	 * @return String the HTML representation of the Roomrateperiods object
	 */
	public function toHTMLString($escapeHTML=true){
		$htmlCode = "<div class=\"roomrateperiods\">\n";
		$htmlCode .= '	<div class="roomrateperiods_ratePeriodCode">'.(($escapeHTML===true) ? htmlspecialchars($this->ratePeriodCode) : $this->ratePeriodCode)."</div>\n";
		$htmlCode .= '	<div class="roomrateperiods_ratePeriodDescription">'.(($escapeHTML===true) ? htmlspecialchars($this->ratePeriodDescription) : $this->ratePeriodDescription)."</div>\n";
		$htmlCode .= "</div>\n";
		return $htmlCode;
	}
	
	public function getData($where) {
		$rows = $this->dao->getData($where);
		return $rows;
	}


	public static function loadAll(){
		$roomrateperiods = new Roomrateperiods();
		$rows = $roomrateperiods->dao->getData("");
		$roomrateperiodss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Roomrateperiods();
			$d->init($rows[$index]);
			array_push($roomrateperiodss,$d);
		}
		return $roomrateperiodss;
	}


	/**
	 * Load the Roomrateperiods uniquely by its primary key.
	 * @param ratePeriodCode the primary key
	 * @return Roomrateperiods Instance of {@link Roomrateperiods}
	 */
	public static function loadUnique($ratePeriodCode){
		$roomrateperiods = new Roomrateperiods();
		$rows = $roomrateperiods->dao->getData("`ratePeriodCode`='$ratePeriodCode'");
		$roomrateperiods->init($rows[0]);
		return $roomrateperiods;
	}


	/**
	 * Insert this object into the DB
	 * @return number new id (auto increment value) genereated
	 */
	public function insert(){
		$list = array("ratePeriodCode"=>$this->ratePeriodCode, "ratePeriodDescription"=>$this->ratePeriodDescription);
		return $this->dao->insertRecord($list);
	}


	/**
	 * Update this object into the DB
	 * @return number the number of updated records
	 */
	public function update(){
		$list = array("ratePeriodCode"=>$this->ratePeriodCode, "ratePeriodDescription"=>$this->ratePeriodDescription);
		$where = "`ratePeriodCode`='$ratePeriodCode'";
		return $this->dao->updateRecord($list,$where);
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initPOST(){
		if (isset($_POST['ratePeriodCode'])){
			$this->ratePeriodCode = $_POST['ratePeriodCode'];
		}
		if (isset($_POST['ratePeriodDescription'])){
			$this->ratePeriodDescription = $_POST['ratePeriodDescription'];
		}
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initGET(){
		if (isset($_GET['ratePeriodCode'])){
			$this->ratePeriodCode = $_GET['ratePeriodCode'];
		}
		if (isset($_GET['ratePeriodDescription'])){
			$this->ratePeriodDescription = $_GET['ratePeriodDescription'];
		}
	}


	/**
	 * Returns the value from the database field ratePeriodCode.
	 * In the database the field ratePeriodCode is of type varchar.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getRatePeriodCode(){
		return $this->ratePeriodCode;
	}


	/**
	 * Set the value from the database field ratePeriodCode.
	 * In the database the field ratePeriodCode is of type varchar.
	 * The database field is NOT nullable.
	 * @param ratePeriodCode String with the value for the field to be set
	 */
	public function setRatePeriodCode($ratePeriodCode){
		if(strlen($ratePeriodCode) > 10) throw new Exception("ratePeriodCode does not allow strings longer than 10 characters. The submitted string contains ".strlen($ratePeriodCode)." characters.");
		$this->ratePeriodCode = $ratePeriodCode;
	}


	/**
	 * Returns the value from the database field ratePeriodDescription.
	 * In the database the field ratePeriodDescription is of type varchar.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getRatePeriodDescription(){
		return $this->ratePeriodDescription;
	}


	/**
	 * Set the value from the database field ratePeriodDescription.
	 * In the database the field ratePeriodDescription is of type varchar.
	 * The database field is  nullable.
	 * @param ratePeriodDescription String with the value for the field to be set
	 */
	public function setRatePeriodDescription($ratePeriodDescription){
		if(strlen($ratePeriodDescription) > 45) throw new Exception("ratePeriodDescription does not allow strings longer than 45 characters. The submitted string contains ".strlen($ratePeriodDescription)." characters.");
		$this->ratePeriodDescription = $ratePeriodDescription;
	}
}
?>